<html lang="zh_CN">
{% include "common/table_page_head.html" %}
<body>
<div style="padding: 5px; width: 100%; position: relative; height: 35px;">
    <div style='float:left; height: 30px; margin-right: 5px;'>
        <button class="layui-btn layui-btn-sm layui-btn-normal" onclick="addData()"
                id="addOrgItem"><span
                class='glyphicon glyphicon-plus'></span>&nbsp;新增
        </button>
        <button class="layui-btn layui-btn-sm" onclick="doQuery()">
            <span class='glyphicon glyphicon-repeat'></span>&nbsp;刷新
        </button>
    </div>
    <div class='input-group input-group-sm'
         style='float:left; width:280px; height: 30px; margin-left: 5px;'>
        <input type="text" id="query_text" placeholder="快速查询..."
               class='form-control'>
        <span class='input-group-btn'>
            <button class='btn btn-default' onclick="doQuery()">
                <span class='glyphicon glyphicon-search'></span>查询
            </button>
        </span>
    </div>
</div>
<script type="text/html" id="actionBar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<table lay-filter="datalist" class="layui-table"
       lay-data="{height:'full-60', page:true,even:true, id:'datalist'}" id="datalist">
    <thead>
    <tr>
        <th lay-data="{field:'sid',hide:true}"></th>
        <th lay-data="{field:'sfileid',hide:true}"></th>
        <th lay-data="{field:'sorder',width:60}">序号</th>
        <th lay-data="{field:'sconclusionname'}">意见</th>
        <th lay-data="{field:'screatorname',width:100}">创建人</th>
        <th lay-data="{field:'screatetime', width:160}">创建时间</th>
        <th lay-data="{toolbar:'#actionBar', width:120}">操作</th>
    </tr>
    </thead>
</table>
<div id="editView" style="display:none;padding-right: 20px; padding-top: 20px;">
    <form class="layui-form" action="" id="maindataform">
        <div class="layui-form-item">
            <label class="layui-form-label">序号</label>
            <div class="layui-input-block">
                {{ form.sorder }}
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">意见</label>
            <div class="layui-input-block">
                {{ form.sconclusionname }}
            </div>
        </div>
        <div style="display: none">
            {{ form.sid }}
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                {{ form.csrf_token }}
                {{ form.submit }}
                <button type="reset" class="layui-btn layui-btn-primary" style="display: none">重置</button>
                <button type="button" class="layui-btn layui-btn-primary" onclick="layui.layer.closeAll()">取消</button>
            </div>
        </div>
    </form>
</div>
</body>
<script type="text/javascript">
    let currentRow = {};

    function doQuery() {
        let search_text = $("#query_text").val();
        let surl = '/system/personal/flowset/myOpinion/dataList?search_text=' + J_u_encode(search_text);
        currentRow = {};
        layui.table.reload('datalist', {
            url: surl,
            done: function () {//res, curr, count
                $("#search_text").val(search_text);
            }
        });
    }

    $(document).ready(function () {
        doQuery();
    });


    //触发行单击事件
    layui.table.on('row(datalist)', function (obj) {
        //console.log(obj.tr) //得到当前行元素对象
        //console.log(obj.data) //得到当前行数据
        obj.tr.parent().find('tr').removeClass('active')
        obj.tr.addClass('active') //选中行加特殊背景颜色
        currentRow = obj.data;
    });

    //监听行工具事件
    layui.table.on('tool(datalist)', function (obj) {
        //console.log(obj)
        let data = obj.data;
        if (obj.event === 'edit') {
            editData(data);
        }
        if (obj.event === 'del') {
            delData(data);
        }
    });


    function addData() {
        J$("maindataform").reset();
        layui.layer.open({
            title: '添加',
            type: 1,
            area: ['400px', '300px'],
            content: $('#editView')
        });
    }

    function editData(data) {
        $("#sorder").val(data.sorder);
        $("#sconclusionname").val(data.sconclusionname);
        $("#sid").val(data.sid);
        layui.layer.open({
            title: '编辑',
            type: 1,
            area: ['400px', '300px'],
            content: $('#editView')
        });
    }

    function delData(data) {
        layui.layer.confirm("文件删除后不能恢复，确认删除吗？", function () {
            $.ajax({
                url: "/system/personal/flowset/myOpinion/deleteData",
                type: "post",
                async: true,
                data: {rowid: data.sid},
                dataType: "json",
                success: function (re) {
                    if (re.state === true) {
                        layui.layer.msg("删除成功！");
                        doQuery();
                    } else {
                        layui.layer.alert("删除失败：" + re.msg);
                    }
                }
            });
        });
    }

    layui.form.on('submit(mainform)', function (data) {
        //console.log(data.field)
        $.ajax({
            url: "/system/personal/flowset/myOpinion",
            type: "post",
            async: false,
            data: data.field,
            dataType: "json",
            success: function (re) {
                if (re.state === true) {
                    layui.layer.closeAll();
                    layui.layer.msg("保存成功！")
                    doQuery();
                } else {
                    layui.layer.alert("保存失败：" + re.msg);
                }
            }
        });
        return false;
    });
</script>
</html>